package com.jcode222.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

// http://localhost:8080/swagger-ui.html
// http://localhost:8080/swagger-ui/index.html
@EnableSwagger2
@Configuration
public class Swagger2Config {

    @Value("${spring.swagger2.enabled}")
    private Boolean enable;

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("Spring Boot 2.0 整合 Sharding-JDBC + MyBatis-Plus 示例")
                        .description("这是一个基于 Spring Boot 2.0 整合 Sharding-JDBC + MyBatis-Plus 的示例项目，用于演示如何在 Spring Boot 2.0 中使用 Sharding-JDBC 进行数据库分表和 MyBatis-Plus 进行数据库操作。")
                        .version("1.0.0")
                        .build())
                .enable(enable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jcode222.controller"))
                .paths(PathSelectors.any())
                .build();
    }
}
